package com.yuncheng.spcyApi.spcy;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.service.ISpcyRsYwzdxxService;
import com.yuncheng.spcyApi.service.ISpcySqsxBaiscService;
import com.yuncheng.spcyApi.spcyService.SpcyFlfgService;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.spcyApi.spcyService.SpcyService;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@Api(tags = "法律法规接口")
@RestController
@RequestMapping("/api/spzx-spcy/flfg")
public class SpcyFlfgController {

    @Resource
    private SpcyFlfgService spcyFlfgService;

    @Resource
    private ISpcyRsYwzdxxService spcyRsYwzdxxService;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    @Resource
    private SpcyService spcyService;

    @Log(title = "指导文件-分页查询")
    @ApiOperation(value = "指导文件-分页查询")
    @GetMapping("queryPageZdwj")
    public HttpResult queryPageZdwj(SpcyFgZdwj zdwj, PageVo pageVo){
        return spcyFlfgService.queryPageZdwj(zdwj,pageVo.getPageNo(),pageVo.getPageSize());
    }

    @Log(title = "获取对应法规列表-根据指导文件id")
    @ApiOperation(value = "获取对应法规列表-根据指导文件id")
    @GetMapping("queryListFgByZdwjId")
    public HttpResult queryListFgByZdwjId(@RequestParam(name = "fzdwjid", defaultValue = "") String fzdwjid){
        return spcyFlfgService.queryListFgByZdwjId(fzdwjid);
    }

    @Log(title = "获取章节（树形）列表-根据法规id")
    @ApiOperation(value = "获取章节（树形）列表-根据法规id")
    @GetMapping("queryListZjTreeByFgId")
    public HttpResult queryListZjTreeByFgId(@RequestParam(name = "ffgid", defaultValue = "") String ffgid){
        return spcyFlfgService.queryListZjTreeByFgId(ffgid);
    }

    @Log(title = "获取条款分页列表-根据章节id")
    @ApiOperation(value = "获取条款分页列表-根据章节id")
    @GetMapping("queryPageTkListByZjId")
    public HttpResult queryPageTkListByZjId(SpcyFgTk tk, PageVo pageVo){
        return spcyFlfgService.queryPageTkListByZjId(tk, pageVo.getPageNo(), pageVo.getPageSize());
    }

    /*@Log(title = "获取指导原则分页列表-根据章节id")
    @ApiOperation(value = "获取指导原则分页列表-根据章节id")
    @GetMapping("queryPageZdyzListByZjId")*/
    public HttpResult queryPageZdyzListByZjId(SpcyFgZdyz zdyz, PageVo pageVo){
        return spcyFlfgService.queryPageZdyzListByZjId(zdyz, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "获取指导原则分页列表-根据条款id")
    @ApiOperation(value = "获取指导原则分页列表-根据条款id")
    @GetMapping("queryPageZdyzListByTkId")
    public HttpResult queryPageZdyzListByTkId(SpcyFgZdyz zdyz, PageVo pageVo){
        return spcyFlfgService.queryPageZdyzListByTkId(zdyz, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "获取模版分页列表-根据章节id")
    @ApiOperation(value = "获取模版分页列表-根据章节id")
    @GetMapping("queryPageMbListByZjId")
    public HttpResult queryPageMbListByZjId(SpcyFgZjmsmb mb, PageVo pageVo){
        return spcyFlfgService.queryPageMbListByZjId(mb, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "指导文件-查看详情界面-根据指导文件id")
    @ApiOperation(value = "指导文件-查看详情界面-根据指导文件id")
    @GetMapping("viewZdwjByZdwjId")
    public HttpResult viewZdwjByZdwjId(@RequestParam(name = "fzdwjid", defaultValue = "") String fzdwjid){
        return HttpResult.ok(spcyFlfgService.viewZdwjByZdwjId(fzdwjid));
    }

    @Log(title = "查看指导文件详情界面-根据申请事项id")
    @ApiOperation(value = "查看指导文件详情界面-根据申请事项id")
    @GetMapping("viewInfo")
    public HttpResult viewInfo(@RequestParam(name = "sqsxid", defaultValue = "SQSXID") String sqsxid){
        String fzdwjid = spcyRsYwzdxxService.querySqsxZdywId(spcySqsxBaiscService.getYwflCodeBySqsxId(sqsxid));
        return HttpResult.ok(spcyFlfgService.viewZdwjByZdwjId(fzdwjid));
    }

    @Log(title = "获取章节树形列表-根据申请事项id")
    @ApiOperation(value = "获取章节树形列表-根据申请事项id")
    @GetMapping("queryZjTreeList")
    public HttpResult queryZjTreeList(@RequestParam(name = "sqsxid", defaultValue = "SQSXID") @ApiParam("申请事项id") String sqsxid,
                                      @RequestParam(value = "gjz",defaultValue = "") @ApiParam("关键字") String gjz){
        String fzdwjid = spcyRsYwzdxxService.querySqsxZdywId(spcySqsxBaiscService.getYwflCodeBySqsxId(sqsxid));
        return spcyFlfgService.getZjTree(fzdwjid, gjz);
    }

    @Log(title = "获取条款列表-根据章节目录ID")
    @ApiOperation(value = "获取条款列表-根据章节目录ID")
    @GetMapping("queryTkList")
    public HttpResult queryTkList(@RequestParam(name = "id", defaultValue = "SQSXID") @ApiParam("选中章节目录id") String id,
                                  @RequestParam(value = "gjz",defaultValue = "") @ApiParam("关键字") String gjz,
                                  PageVo pageVo){

        return spcyFlfgService.queryTkList(id, gjz, pageVo);
    }

    @Log(title = "现场检查章节-完成")
    @ApiOperation(value = "现场检查章节-完成")
    @GetMapping(value = "xcjczjwc")
    public HttpResult xcjczjwc(@RequestParam(name = "id", defaultValue = "") String id){

        Result result = spcyFlfgService.xcjczjByWc(id);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "现场检查章节-重新编辑")
    @ApiOperation(value = "现场检查章节-重新编辑")
    @GetMapping(value = "xcjczjcxbj")
    public HttpResult xcjczjcxbj(@RequestParam(name = "id", defaultValue = "") String id){

        Result result = spcyFlfgService.xcjczjcxbj(id);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "查询发现问题-未完成")
    @ApiOperation(value = "查询发现问题-未完成")
    @GetMapping(value = "queryWwcFxwtBySqsxId")
    public HttpResult queryWwcFxwtBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "") @ApiParam("申请事项id") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return HttpResultVo.HttpResultList(spcyFlfgService.selectWwcFxwtBySqsxId(sqsxid));
    }

    @Log(title = "查询发现问题-已完成")
    @ApiOperation(value = "查询发现问题-已完成")
    @GetMapping(value = "queryYwcFxwtBySqsxId")
    public HttpResult queryYwcFxwtBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "") @ApiParam("申请事项id") String sqsxid,
                                           @RequestParam(value = "ffxryid",defaultValue = "") @ApiParam("发现人员id") String ffxryid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return HttpResultVo.HttpResultList(spcyFlfgService.selectYwcFxwtBySqsxId(sqsxid, ffxryid));
    }

    @Log(title = "修改发现问题序号")
    @ApiOperation(value = "修改发现问题序号")
    @PostMapping(value = "updateWtOrder")
    public HttpResult updateWtOrder(@RequestBody SpcyFgXcjcwt update){

        return spcyFlfgService.updateWtOrder(update);
    }

    @Log(title = "查询发现问题及对应条款依据-根据问题id")
    @ApiOperation(value = "查询发现问题及对应条款依据-根据问题id")
    @GetMapping(value = "queryFxwtJtkById")
    public HttpResult queryFxwtJtkById(@RequestParam(value = "id",defaultValue = "") @ApiParam("问题id") String id){

        return spcyFlfgService.selecyFxwtJtkById(id);
    }

    @Log(title = "更新发现问题-点击完成")
    @ApiOperation(value = "更新发现问题-点击完成")
    @GetMapping(value = "fxwtDjwc")
    public HttpResult fxwtDjwc(@RequestParam(value = "id",defaultValue = "") @ApiParam("问题id") String id){

        Result result = spcyFlfgService.updateFxwtState(id, true);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "更新发现问题-点击重新编辑")
    @ApiOperation(value = "更新发现问题-点击重新编辑")
    @GetMapping(value = "fxwtCxbj")
    public HttpResult fxwtCxbj(@RequestParam(value = "id",defaultValue = "") @ApiParam("问题id") String id){

        Result result = spcyFlfgService.updateFxwtState(id, false);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "发现缺陷情况选择对应的现场检查项目列表")
    @ApiOperation(value = "发现缺陷情况选择对应的现场检查项目列表")
    @GetMapping(value = "fxwtXmList")
    public HttpResult fxwtXmList(@RequestParam(name = "sqsxid", defaultValue = "") @ApiParam("申请事项id") String sqsxid){

        return HttpResultVo.HttpResultGet(spcyFlfgService.quertJczjNameListBySqsxId(sqsxid));
    }

//    @Log(title = "现场检查章节-批量验证是否已完成")
//    @ApiOperation(value = "现场检查章节-批量验证是否已完成")
    @GetMapping(value = "verifyXcjczjWc")
    public HttpResult verifyXcjczjWc(@RequestParam(name = "sqsxid", defaultValue = "") String sqsxid){

        /** 验证是否为组长 */
//        boolean isZz = spcyService.verifyNowUserIsXpryZz(sqsxid);
        return spcyFlfgService.verifyXcjczjWc(sqsxid, true);
    }

//    @Log(title = "现场检查章节-批量完成")
//    @ApiOperation(value = "现场检查章节-批量完成")
    @GetMapping(value = "xcjczjplwc")
    public HttpResult xcjczjplwc(@RequestParam(name = "sqsxid", defaultValue = "") String sqsxid){

        /** 验证是否为组长 */
//        boolean isZz = spcyService.verifyNowUserIsXpryZz(sqsxid);
        Result result = spcyFlfgService.xcjczjByPlwc(sqsxid, true);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "获取现场检查章节数据-根据章节id")
    @ApiOperation(value = "获取现场检查章节数据-根据章节id")
    @GetMapping(value = "hqxczj")
    public HttpResult hqxczjById(@RequestParam(value = "id",defaultValue = "") String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        return spcyFlfgService.hqxczjById(id);
    }

    @Log(title = "查询当前问题条款-根据当前问题id")
    @ApiOperation(value = "查询当前问题条款-根据当前问题id")
    @GetMapping(value = "queryWttkList")
    public HttpResult queryWttkList(@RequestParam(name = "fxcjcwtid", defaultValue = "") @ApiParam("问题id") String fxcjcwtid){

        return HttpResultVo.HttpResultList(spcyFlfgService.selectXcjcwtTkList(fxcjcwtid));
    }

    @Log(title = "新增法律法规指导文件")
    @ApiOperation(value = "新增法律法规指导文件")
    @PostMapping("addZdwj")
    public HttpResult addZdwj(@RequestBody SpcyFgZdwj bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addZdwj(bean));
        return result;
    }

    @Log(title = "更新法律法规指导文件")
    @ApiOperation(value = "更新法律法规指导文件")
    @PutMapping("updateZdwj")
    public HttpResult updateZdwj(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateZdwj(map);
       return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规指导文件")
    @ApiOperation(value = "删除法律法规指导文件")
    @DeleteMapping("deleteZdwj")
    public HttpResult deleteZdwj(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteZdwj(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "新增法律法规")
    @ApiOperation(value = "新增法律法规")
    @PostMapping("addFgmc")
    public HttpResult addFgmc(@RequestBody SpcyFgFgmc bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addFgmc(bean));
        return result;
    }

    @Log(title = "更新法律法规")
    @ApiOperation(value = "更新法律法规")
    @PutMapping("updateFgmc")
    public HttpResult updateFgmc(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateFgmc(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规")
    @ApiOperation(value = "删除法律法规")
    @DeleteMapping("deleteFgmc")
    public HttpResult deleteFgmc(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteFgmc(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "新增法律法规章节")
    @ApiOperation(value = "新增法律法规章节")
    @PostMapping("addZjml")
    public HttpResult addZjml(@RequestBody SpcyFgZjml bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addZjml(bean));
        return result;
    }

    @Log(title = "新增下级法律法规章节")
    @ApiOperation(value = "新增下级法律法规章节")
    @PostMapping("addZjmlInSub")
    public HttpResult addZjmlInSub(@RequestBody SpcyFgZjml bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addZjmlInSub(bean));
        return result;
    }

    @Log(title = "更新法律法规章节")
    @ApiOperation(value = "更新法律法规章节")
    @PutMapping("updateZjml")
    public HttpResult updateZjml(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateZjml(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规章节")
    @ApiOperation(value = "删除法律法规章节")
    @DeleteMapping("deleteZjml")
    public HttpResult deleteZjml(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteZjml(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "新增法律法规条款")
    @ApiOperation(value = "新增法律法规条款")
    @PostMapping("addTk")
    public HttpResult addTk(@RequestBody SpcyFgTk bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addTk(bean));
        return result;
    }

    @Log(title = "更新法律法规条款")
    @ApiOperation(value = "更新法律法规条款")
    @PutMapping("updateTk")
    public HttpResult updateTk(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateTk(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规条款")
    @ApiOperation(value = "删除法律法规条款")
    @DeleteMapping("deleteTk")
    public HttpResult deleteTk(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteTk(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "新增法律法规指导原则")
    @ApiOperation(value = "新增法律法规指导原则")
    @PostMapping("addZdyz")
    public HttpResult addZdyz(@RequestBody SpcyFgZdyz bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addZdyz(bean));
        return result;
    }

    @Log(title = "更新法律法规指导原则")
    @ApiOperation(value = "更新法律法规指导原则")
    @PutMapping("updateZdyz")
    public HttpResult updateZdyz(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateZdyz(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规指导原则")
    @ApiOperation(value = "删除法律法规指导原则")
    @DeleteMapping("deleteZdyz")
    public HttpResult deleteZdyz(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteZdyz(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "新增法律法规描述模版")
    @ApiOperation(value = "新增法律法规描述模版")
    @PostMapping("addMsmb")
    public HttpResult addMsmb(@RequestBody SpcyFgZjmsmb bean){

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(spcyFlfgService.addMsmb(bean));
        return result;
    }

    @Log(title = "更新法律法规描述模版")
    @ApiOperation(value = "更新法律法规描述模版")
    @PutMapping("updateMsmb")
    public HttpResult updateMsmb(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updateMsmb(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除法律法规描述模版")
    @ApiOperation(value = "删除法律法规描述模版")
    @DeleteMapping("deleteMsmb")
    public HttpResult deleteMsmb(@RequestParam(value = "id",defaultValue = "")String id){

        spcyFlfgService.deleteMsmb(id);
        return HttpResult.ok("删除成功");
    }

}
